package com.minimoment.util.ToolAction;

import com.minimoment.base.BaseAction;
import com.minimoment.model.domain.*;
import com.minimoment.model.service.MovieService;
import com.opensymphony.xwork2.ActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * Created by etund on 2014/10/28.
 */
@Controller
@Scope("prototype")
public class IndexAction extends BaseAction<Movie>{

    /**
     * 首页数据显示
     * @return
     * @throws Exception
     */
    public String index() throws Exception {
        System.out.println("=========index=======");
//       准备头条数据3
        movies = this.movieService.getByFlag("head");
        if (movies.size() > 0) {
            System.out.println("============headMovie===============");
//            this.session.put("headMovie",movies);
            ActionContext.getContext().put("headMovie", movies);
        }
//       准备正在热播电影数据23
        movies = this.movieService.getByFlag("now");
        if (movies.size() > 0) {
            System.out.println("============nowMovie===============");
            ActionContext.getContext().put("nowMovie", movies);
        }
//       准备即将上映的电影的数据4
        movies = this.movieService.getByFlag("preview");
        if (movies.size() > 0) {
            System.out.println("============previewMovie===============");
            ActionContext.getContext().put("previewMovie", movies);

        }
//         准备影评数据(找评论数最多的前6条)
        umComents = this.umComentService.findBest(6);
        if (umComents.size() > 0) {
            System.out.println("============umComment===============");
            ActionContext.getContext().put("umComment", umComents);
        }
//      准备电影新闻数据
        movieNewses = this.movieNewsService.findBest(4);
        if (movieNewses.size() > 0) {
            System.out.println("============movieNewses===============");
            ActionContext.getContext().put("movieNewses", movieNewses);
        }

        return "index";
    }


    /**
     * theater页面数据显示
     * @return
     * @throws Exception
     */
    public String theater() throws Exception{
        //       准备头条3
        movies = movieService.getByFlag(2L,2L,3);
        if(movies.size()>0){
            ActionContext.getContext().put("headMovie",movies);
        }
//    查询对应标志的前6条
        movies = movieService.getByFlag(1L,1L,6);
        if(movies.size()>0){
            ActionContext.getContext().put("nowMovie",movies);
        }
//        准备即将上映的电影
        movies = movieService.getByFlag(3L,3L,6);
        if(movies.size()>0){
            ActionContext.getContext().put("previewMovie",movies);
        }
//                准备全部上映电影的数据
        movies = movieService.getByFlag(2L,1L,null);
        if(movies.size()>0){
            ActionContext.getContext().put("currentMovie",movies);
        }
//       准备电影热度排行榜和
        movies = movieService.getByFlag(2L,1L,10);
        if(movies.size()>0){
            ActionContext.getContext().put("hotMovie",movies);
        }
//      最热新片影评
        umComents = this.umComentService.getHot(1L,2L,7);
        if(umComents.size()>0){
            ActionContext.getContext().put("umComents",umComents);
        }
//        准备地区（热门城市）
        areas = this.areaService.getTheAreas("a");
        if(areas.size()>0){
            ActionContext.getContext().put("areas",areas);
        }

//        准备影院数据
        areas = this.areaService.getTown();
        ActionContext.getContext().put("zhanjiang",areas);
        this.theaters = this.theaterService.findAll();
        if(theaters.size()>0){
            ActionContext.getContext().put("allTheater",theaters);
        }

        return "theater";
    }

    /**
     * phantoScope(万花筒页面显示)
     * @return
     * @throws Exception
     */
    public String phantoScope() throws Exception{
//        准备页面影讯数据
        this.telecines = this.telecineService.findAll();
        if(telecines.size()>0){
            ActionContext.getContext().put("allTelecines",telecines);
        }
//        准备最热读物的数据 准备影讯，电影新闻，很影片个3条评论数最多的
       this.movieNewses =  this.movieNewsService.findTop(8);
        if(movieNewses.size()>0){
            ActionContext.getContext().put("topMovieNews",movieNewses);
        }
        return "phantoScope";
    }
}
